using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using OpenTK.Math;

namespace Dogfight2008.Common.Tests
{
  [TestFixture]
  public class CalcFixture
  {
    [Test]
    public void Equal_Vector3()
    {
      Assert.IsTrue(Calc.Equal(Vector3.UnitZ, Vector3.UnitZ));
    }

    [Test]
    public void NotEqual_Vector3()
    {
      Assert.IsFalse(Calc.Equal(Vector3.UnitZ, Vector3.UnitX));
    }

    [Test]
    public void AlmostEqual_Vector3()
    {
      Vector3 v2 = Vector3.UnitZ;
      v2.X += 0.0000001f;
      Assert.IsTrue(Calc.AlmostEqual(Vector3.UnitZ, v2));
    }

    [Test]
    public void AlmostEqual_Vector3_2()
    {
      Assert.IsFalse(Calc.Equal(Vector3.UnitZ, Vector3.UnitX));
    }

    [Test]
    public void AlmostEqualFloat()
    {
      Assert.IsTrue(Calc.AlmostEqual(1, 1.0000001f));
    }

    [Test]
    public void AlmostEqualFloat2()
    {
      Assert.IsFalse(Calc.AlmostEqual(1, 2));
    }

    [Test]
    public void Polar()
    {
      double angle = Calc.DegreesToRadians(30);
      Vector2 v = Calc.Polar(angle, 10);
      Vector2 exp = Calc.v(Math.Cos(angle) * 10, Math.Sin(angle) * 10);
      Assert.AreEqual(exp.X, v.X);
      Assert.AreEqual(exp.Y, v.Y);
    }

    [Test]
    public void D2R()
    {
      Assert.AreEqual(0, Calc.DegreesToRadians(0), 0.01f);
      Assert.AreEqual(Math.PI, Calc.DegreesToRadians(180), 0.01f);
    }
  }
}
